import { Message, Type } from "protobufjs";
import JNSyncFrameComponent from "./JNSyncFrameComponent";
import NGameMessage from "../../../util/NGameMessage";

export default abstract class JNSyncFrameProtoComponent<Input> extends JNSyncFrameComponent<Input> {

    TYPE:Type;
    
    onLoad(){
        if(this.getClassName()){
            this.TYPE = NGameMessage.getIns().getType(this.getClassName());
        }
        super.onLoad();
    }

    getClassName():string {return null};

    //解析
    decoder(bytes:Uint8Array):Input{
        if(this.TYPE){
            return this.TYPE.decode(bytes) as Input;
        }else{
            return {} as any;
        }
    }

    //编码
    encoder(input:Input):Uint8Array{
        return this.TYPE.encode(input).finish();
    }

}

